package com.ak.cluster;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.ak.player.Player;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Json;

/**
 * Item Reader
 * @author James Roosevelt -- With revisions by Tyler Kirk
 * 
 * 	This class reads in JSON files.
 */

public class ItemReader {
	
	//This is stored and held in local class scope rather than instantiated in local constructor scope.
	public Json json;
	public List<Object>inputList = new ArrayList<Object>();
	Array<int[]> array = new Array<int[]>(123);
	
	public ItemReader(Player player)
	{
		//Just assign directly to instantiate. 
		json = new Json();
		
		//json.setElementType(String.class, "userName",Player.class);
		
		 //works//
		if(!Gdx.files.external("Player.json").exists())
			if(Gdx.files.isExternalStorageAvailable())
				json.toJson(player.playerData, Gdx.files.external("Player.json"));
		//Gdx.files.external("Player.json").writer(false);
			//json.toJson(player.playerData, HashMap.class , Gdx.files.external("Player.json"));
		 //works//
		// .json example
		// {"name":"value","items":[1,2,3],"nested":{"more":"stuff"}}
	}	
	
	@SuppressWarnings("unchecked")
	public void load(Player lPlayer)
	{
		lPlayer.playerData = json.fromJson(HashMap.class, Gdx.files.external("Player.json"));	
	}
	public void save(Player lPlayer)
	{
		json.toJson(lPlayer.playerData, HashMap.class , Gdx.files.external("Player.json"));
	}

}


// commit notes 
// need to add this line: ItemReader iR = new ItemReader();
// to the assetmanager
// and this line: 	public static String reader		= "text.json";
// to the assetindex